package com.mall.alipay.controller;

import com.mall.alipay.common.Constant;
import com.mall.alipay.common.R;
import com.mall.alipay.common.ResultCodeEnum;
import com.mall.alipay.mapper.GoodsMapper;
import com.mall.alipay.mapper.OrdersMapper;
import com.mall.alipay.entity.Orders;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Resource
    private GoodsMapper goodsMapper;

    @Resource
    private OrdersMapper ordersMapper;

    /**
     * 商品列表
     * @return
     */
    @GetMapping("/orders")
    public R getOrders() {
        return R.setResult(ResultCodeEnum.SUCCESS).data(ordersMapper.selectList(null));
    }

    /**
     * 取消订单
     * @param orders
     * @return
     */
    @PostMapping("/cancellationOfOrder")
    public R cancellationOfOrder(@RequestBody Orders orders){
        //
        orders.setState(Constant.ORDER_STATUS_CANCEL);
        int status = ordersMapper.updateById(orders);

        if (status <= 0) {
             return R.setResult(ResultCodeEnum.UPDATE_ERROR);
        }
        return R.ok();
    }
}
